﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
	public partial class EnderecoX : System.Web.UI.UserControl
	{
		public string TituloEndereco
		{
			get
			{
				return litNome.Text;
			}
			set
			{
				litNome.Text = value;
			}
		}

		public void BuscaCEP(string cep)
		{
			WSEndereco.AddressServiceCepAddressBinding servicoCep = new WSEndereco.AddressServiceCepAddressBinding();
			WSEndereco.CepAddressResult resultCep = servicoCep.CepAddress(cep);

			//resultCep = this.MokaDados(resultCep);

			if (resultCep != null && resultCep.address != null)
			{
				litCEP.Text = cep;
				lblBairro.Text = resultCep.address.bairro;
				lblLocalidade.Text = resultCep.address.localidade;
				lblLogradouro.Text = resultCep.address.logradouro;
				lblUf.Text = resultCep.address.uf;
				panelEndereco.Visible = true;
				panel1.Visible = false;
			}
			else
			{
				panelEndereco.Visible = false;
				string textoErro = string.Empty;
				foreach (WSEndereco.AddressError erro in resultCep.errors)
				{
					textoErro += erro.description + "</BR>";
				}
				lblErro.Text = textoErro;
				panel1.Visible = true;
			}
		}

		//private WSEndereco.CepAddressResult MokaDados(WSEndereco.CepAddressResult resultCep)
		//{
		//    resultCep = new WSEndereco.CepAddressResult();
		//    resultCep.address = new WSEndereco.Address();
		//    resultCep.address.bairro = "bairro teste";
		//    resultCep.address.cep = "12322-000";
		//    resultCep.address.localidade = "localidade teste";
		//    resultCep.address.logradouro = "logradouro teste";
		//    resultCep.address.uf = "SP";

		//    return resultCep;
		//}

	}
}